package com.python.project2.service.impl;

import com.python.project2.db.domain.*;
import com.python.project2.db.mapper.MarketAdMapper;
import com.python.project2.db.mapper.MarketCategoryMapper;
import com.python.project2.db.mapper.MarketCouponMapper;
import com.python.project2.service.HomeService;
import com.python.project2.vo.ChannelVO;
import com.python.project2.vo.CouponVO;
import com.python.project2.vo.IndexVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description
 * @Date 2023/4/1
 * @Author lixian
 **/
@Service
public class HomeServiceImpl implements HomeService {

	@Autowired
	private MarketAdMapper admapper;

	@Autowired
	private MarketCategoryMapper categoryMapper;

	@Autowired
	private MarketCouponMapper couponMapper;


	@Override
	public IndexVO getIndexInfo() {
		IndexVO indexVO = new IndexVO();
		List<MarketAd> marketAdList = admapper.selectByExampleSelective(new MarketAdExample().createCriteria().andPositionEqualTo(new Byte("1")).andDeletedEqualTo(false).example(), MarketAd.Column.id, MarketAd.Column.name, MarketAd.Column.link, MarketAd.Column.url, MarketAd.Column.position, MarketAd.Column.content, MarketAd.Column.enabled, MarketAd.Column.addTime, MarketAd.Column.updateTime, MarketAd.Column.deleted);
		List<MarketCategory> categoryList = categoryMapper.selectByExampleSelective(new MarketCategoryExample().createCriteria().andPidEqualTo(0).andDeletedEqualTo(false).example(), MarketCategory.Column.id, MarketCategory.Column.iconUrl, MarketCategory.Column.name);
		List<ChannelVO> channelVOList = categoryList.stream().map(ChannelVO::new).collect(Collectors.toList());
		List<MarketCoupon> couponList = couponMapper.selectByExampleSelective(new MarketCouponExample().createCriteria().andDeletedEqualTo(false).example(), MarketCoupon.Column.id, MarketCoupon.Column.name, MarketCoupon.Column.desc, MarketCoupon.Column.tag, MarketCoupon.Column.min, MarketCoupon.Column.days, MarketCoupon.Column.discount);
		List<CouponVO> couponVOList = couponList.stream().map(CouponVO::new).collect(Collectors.toList());
		indexVO.setChannel(channelVOList);
		indexVO.setBanner(marketAdList);
		indexVO.setCouponList(couponVOList);
		return indexVO;
	}
}
